package com.wuhao.shootclient.ui.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wuhao.shootclient.R;
import com.wuhao.shootclient.adapter.SocketAdapter;
import com.wuhao.shootclient.adapter.ToaAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * socket  dialog 调试专用
 */
public class SocketDialog extends Dialog implements View.OnClickListener {

    private RecyclerView rvSeismicValuep;

    private Button btCancel;

    private Context context;

    private SocketAdapter adapter;

    private List<String> list = new ArrayList<>();
    public SocketDialog(@NonNull Context context) {
        super(context,R.style.ThresholdDialog);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.socket_dialog);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        initView();
        initData();
    }

    private void initView() {
        rvSeismicValuep = findViewById(R.id.rv_seismic_value);
        btCancel = findViewById(R.id.bt_cancel);
        btCancel.setOnClickListener(this);
    }

    private void initData() {
        if (list != null && list.size() != 0) {
            rvSeismicValuep.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
            adapter = new SocketAdapter(list);
            rvSeismicValuep.setAdapter(adapter);
            rvSeismicValuep.scrollToPosition(adapter.getItemCount() - 1);
        }
    }

    public void setListRefresh(List<String> list) {
        adapter.setNewData(list);
        rvSeismicValuep.scrollToPosition(adapter.getItemCount() - 1);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bt_cancel:
                dismiss();
                break;
        }
    }

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
    }
}
